require.config(r_config);
require(['common','user_info','mylayer','loginReg'], function (md_common,user_info,mylayer,md_loginReg){
	var user_post={
		init:function(){
			var _this=this;
			user_info.init(this);
			//加载发布笔记
			$(".upload_post").off("click").on("click",function(){
				md_common.uploadPost(this,function(rst){
					$(".share_list_add").after(rst.post_info);
					$(".water_container .lazy").lazyload({
					    threshold : 200
					});
				});
			});
		},
		editItem:function(){
			var id=$(this).attr("data-id");
			var that=this;
			var index=mylayer.showLoad(true);
			var loadUpload=function(md_post_add){
				if($(".layer_post_edit").size()>0){
					mylayer.closeLayer(index);
					//显示发布笔记
					$(".overlay_layer_post_add").show();
					$(".layer_post_add").show();
					$("html,body").css("overflow-y", "hidden");
				}
				else{
					$.postAjax("/post/load",{'id':id},function(result){
						mylayer.closeLayer(index);
						if(result.code=="0x00001"){
							md_loginReg.showLogin();//显示登录
							//设置登录完成事件
							md_loginReg.initSuccess(function(){
								$(that)[0].click();
							});
							return false;
						}
						if(result.code=="0x00000"){
							//显示发布笔记
							$(".overlay_layer_post_add").remove();
							$(".layer_post_add").remove();
							var lay=mylayer.init({
								title:'',
								content:result.data,
								isHeight:true,
								closeFixed:true,
								class_name:"layer_post_add",
								phoneCover:true,
								layerClose:true,
								success:function(){
									$("html,body").css("overflow-y","hidden");
									if(typeof md_post_add!="undefined"){
										var op={
											success:function(rst){
												if(rst.post_list){
												   if(rst.post_list.image){
												   		$("#share_list_"+id).find(".post_image").attr('src',rst.post_list.image);
												   		$("#share_list_"+id).find(".title_info").html(rst.post_list.title);
												    }
												   
												}
											}
										}
										md_post_add.init(op);
									}
								},
								closeEvent:function(){
									$("html,body").css("overflow-y","auto");
								}
							});
							$("#layerBox"+lay).css({'top':"10px","margin-top":"0px"});
						}
					});
				}
			}
			require(['post_add'], function (md_post_add){
		　　　　loadUpload(md_post_add);
		　　});
		},
		removeItem:function(){
			var that=this;
			var id=$(this).attr("data-id");
			mylayer.showConfirm("Are you sure to remove this item",function(){
				$.postAjax("/post/remove",{'id':id},function(rst){
					if(rst.code=="0x00001"){
		  				md_loginReg.showLogin();//显示登录
						//设置登录完成事件
						md_loginReg.initSuccess(function(){
							$(that)[0].click();
						});
						return false;
		  			}
		  			else if(rst.code=="0x00000"){
		  				$("#share_list_"+id).remove();
		  			}
				});
			});
		}
	}
	user_post.init();
});
